<?php
	
	//导入
	include ('header.php');
	//页面格式
	header('content-type:text/html;charset=utf8');
	//header('content-type:application/json;charset=utf8');
	
	//判断session
	if(!isset($_SESSION)){
    session_start();
	}
	$agent = check_wap();
	if($agent){
	
	}else{
		
		include ('caidanlan.php');
}
	
	$cid = $_SESSION["cid"];
	
	//接受参数并操作数据库
	if (isset($_GET["account"]))
 	{
		$account=$_GET["account"];
	}
	else
	{
		$account="";
	}
	if($account=="" || $account==null)
	{
		
	}
	else if($account=="" || $account==null)
	{
		
	}else
	{
		mysql_select_db("che2");
		mysql_query("set names 'utf8'");
		$deletesql="delete from a00user where uid=\"$account\"";
		mysql_query($deletesql);
		
		$sqla1="select uname from a00user where uid=\"$account\"";
		$sqla2=mysql_query($sqla1);
		$sqla3=mysql_num_rows($sqla2);
		if($sqla3>0)
		{
			echo "<script>"."alert('删除失败')"."</script>";
			redirect('usermanage.php');
		}else
		{
			echo "<script>"."alert('删除成功')"."</script>";
			redirect('usermanage.php');
		}
	}
	
	
	if (isset($_GET["yonghu1"]))
 	{
		$yonghu1=$_GET["yonghu1"];
	}
	else
	{
		$yonghu1="";
	}
	if (isset($_GET["yonghu2"]))
 	{
		$yonghu2=$_GET["yonghu2"];
	}
	else
	{
		$yonghu2="";
	}
	if (isset($_GET["xinmima"]))
 	{
		$xinmima=$_GET["xinmima"];
	}
	else
	{
		$xinmima="";
	}
	
	if($yonghu1=="" || $yonghu1 ==null and $yonghu2=="" || $yonghu2 ==null and $xinmima=="" || $xinmima ==null)
	{
		
	}
	else if($yonghu1=="" || $yonghu1 ==null)
	{
		
	}
	else if($yonghu2=="" || $yonghu2 ==null)
	{
		
	}
	else if($xinmima=="" || $xinmima ==null)
	{
		
	}
	else
	{
		mysql_select_db("che2");
		mysql_query("set names 'utf8'");
		$updatesql="update a00user set pass=\"$xinmima\" where c_id=\"$cid\" and uid=\"$yonghu1\"";
		mysql_query($updatesql);
		
		$sqlmima="select uname from a00user where  c_id=\"$cid\" and uid=\"$yonghu1\" and pass=\"$xinmima\"";
		$sqlmima1=mysql_query($sqlmima);
		$sqlmima2=mysql_num_rows($sqlmima1);
		if($sqlmima2>0)
		{
			echo "<script>"."alert('密码修改成功')"."</script>";
		}
		else
		{
			echo "<script>"."alert('密码修改失败')"."</script>";
		}
			
	}
	
	
	if(isset($_GET["uname"]) and $_GET["uname"]!="" and $_GET["uname"]!=null)
	{
		$uname=($_GET["uname"]);
		mysql_select_db("che2");
		mysql_query("set names 'utf8'");
		$querysql="select uid,uname from a00user where c_id=\"$cid\" and ugb > -1 and jihuo = 1 and uname LIKE '%$uname%'";
	}
	else
	{
		mysql_select_db("che2");
		mysql_query("set names 'utf8'");
		$querysql="select uid,uname from a00user where c_id=\"$cid\" and ugb > -1 and jihuo = 1";
	}
		
	
	
	
	//整体页面
	//echo $querysql;
	$querysql1=mysql_query($querysql);
	
echo <<<end5
<a href="address.php">
<i class="icon-home icon-2x"></i> 
</a>
<i class=" icon-caret-right icon-large"></i>

<a href="usermanage.php">用户管理</a>

end5;
	
	
	
	echo <<<end1
	<div class="well">

	
    <a href="adduser.php"><span class="zitiyangshi"> 添加单个用户</span></a>
	||
    <a href="plyonghu.php"><span class="zitiyangshi">  批量添加用户</span></a>
	
	<br>
	<br>
    <form action="usermanage.php" method="GET">

	<div>用户名:
	<input class="text" name="uname">
	</div>

	<input type="submit" values="提交"> 

	
	<br>
	<br>

	<table class="table">
	<tr>
	<th>用户id</th>
	<th>用户名</th>
	<th>操作</th>
	</tr>
end1;
	
	while ($querysql2=mysql_fetch_row($querysql1))
	{
		echo "<tr>";

		echo "<td>$querysql2[0]</td>";
		echo "<td>$querysql2[1]</td>";
	
		echo "<td><a href='javascript:void(0)' onclick='update(this);' >修改密码</a>||<a href='usermanage.php?account=$querysql2[0]'>删除</a></td>";
		//echo "<td><a href='usermaker.php'>修改密码</a>\<a href='userdelete.php'>删除</a></td>";
		echo "</tr>";
	}
	
	echo "</table></div>";
	
	//模态框
	  echo <<<end2
	<div class="modal fade" id="myModala2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
		<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
					&times;
				</button>
				<h4 class="modal-title" id="myModalLabel">
					修改密码
				</h4>
			</div>
			<div class="modal-body">
			<form  action="usermanage.php" method="GET">
				<div>
				用户id：
				<input type="text" id='yonghu1' name='yonghu1' readonly="readonly">
				</div>
				
				<div>
				用户名：
				<input type="text" id='yonghu2' name='yonghu2' readonly="readonly">
				</div>
				
				<div>
				新密码：
				<input type="text" id='xinmima' name='xinmima'>
				</div>
				
				<input type="submit" values="确定">
				<form>	
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭
				</button>
		
			</div>
		</div><!-- /.modal-content -->
	</div><!-- /.modal -->
</div>

end2;


//js
echo <<<enda1
	<script src="http://cdn.bootcss.com/twitter-bootstrap/3.0.3/js/bootstrap.min.js"></script>
	<script>
	function update(obj){
		var tds=$(obj).parent().parent().find('td');
		
		$('#yonghu1').val(tds.eq(0).text());		
		$('#yonghu2').val(tds.eq(1).text());
		
		$('#myModala2').modal('show');
		
	}
</script>


enda1;

include 'bottom.php';
	
?>